package com.vict.task.utils;

import com.vict.task.core.impl.LocalTaskExecuteProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

@Component
public class LocalTaskExecuteUtil {
    public static LocalTaskExecuteProcessor localTaskExecuteProcessor;

    @Autowired
    public void setTaskExecuteProcessor(LocalTaskExecuteProcessor localTaskExecuteProcessor){
        LocalTaskExecuteUtil.localTaskExecuteProcessor = localTaskExecuteProcessor;
    }

    public static void startTaskExecuteProcessor(String type){
        localTaskExecuteProcessor.startTaskExecuteProcessor(type);
    }

    public static <T> void sendTask(String type, T t){
        localTaskExecuteProcessor.sendTask(type, t, new Timestamp(System.currentTimeMillis()), true);
    }

    public static <T> void sendTask(String type, T t, Timestamp actionTime){
        localTaskExecuteProcessor.sendTask(type, t, actionTime, true);
    }

    public static <T> void sendTaskSync(String type, T t){
        localTaskExecuteProcessor.sendTask(type, t, new Timestamp(System.currentTimeMillis()), false);
    }
}
